﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;

namespace NetCoreCMS.Web.Areas.Web.Controllers
{
    public class RegisterController : BaseController
    {
        public string action = string.Empty;
        public IUser_codeService _user_code { get; set; }
        public IActionResult Index(string pid)
        {
            action = Request.Query["act"];
            //检查是否关闭会员注册服务
            if (string.IsNullOrEmpty(action) && uconfig.regstatus == 0)
            {
                return Redirect("/Web/Register/Index?action=close");
            }
            //Email验证
            if (action == "checkmail")
            {
                string code = Request.Query["code"];
                User_code model = _user_code.GetModel(code);
                if (model == null) //返回出错
                {
                    return Redirect("/Web/Register/Index?action=checkerror");
                }
                //修改申请码状态
                model.status = 1;
                _user_code.Update(model);
                //修改用户状态
                _users.UpdateField(model.user_id, "status=0");
            }
            ViewBag.Action = action;
            if (!string.IsNullOrEmpty(pid))
                pid = "test";
            ViewBag.UserName = pid;
            return View();
        }
    }
}